321 - The New Villa (Grafos, BFS, bitwise)
[andmenj-acm.git] / 713 - Adding reversed numbers / 713.cpp
blob480e1f8a1199cf4217b430621a176d2d9c0e6f42
1 #include <vector>
2 #include <iostream>
3 #include <algorithm>
6 using namespace std;
8 int main(){
9 int S;
10 cin >> S;
11 while (S--){
12 string s, t, r="";
13 cin >> s >> t;
14 while (s.size() > 1 && s[s.size()-1] == '0') s.erase(s.size()-1);
15 while (t.size() > 1 && t[t.size()-1] == '0') t.erase(t.size()-1);
16 int n = max(s.size(), t.size());
17 int carry = 0;
18 for (int i=0; i<n; ++i){
19 int x = carry;
20 if (i < s.size()){
21 x += s[i] - '0';
23 if (i < t.size()){
24 x += t[i] - '0';
26 carry = x/10;
27 x %= 10;
28 r += x + '0';
30 if (carry) r += carry + '0';
31 while (r.size() > 1 && r[0] == '0'){
32 r.erase(0, 1);
34 cout << r << endl;
37 return 0;